package com.raos.example.web;

import com.raos.example.Service.RocketMQProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Rocket 消息测试Controller
 *
 * @author raos
 * @date 2025-02-28
 */
@RequestMapping("/")
@RestController
public class TestController {

    @Autowired
    private RocketMQProducer producer;

    @RequestMapping
    public String index() {
        return System.currentTimeMillis() + "";
    }

    /**
     * 测试 mq普通消息
     */
    @RequestMapping("/sendMessage")
    public String sendMessage(@RequestParam(name = "topic", required = false, defaultValue = "generalTopic") String topic,
                              String message) {
        producer.sendMessage(topic, message);
        return String.format("时间：%s，发送mq普通消息...", System.currentTimeMillis());
    }

    /**
     * 测试 mq延迟消息
     */
    @RequestMapping("/sendDelayMessage")
    public String sendDelayMessage(@RequestParam(name = "topic", required = false, defaultValue = "delayTopic") String topic,
                              String message, long delayMillis) {
        producer.sendDelayMessage(topic, message, delayMillis);
        return String.format("时间：%s，发送mq延迟消息，延迟时间：%s...", System.currentTimeMillis(), delayMillis);
    }

}
